package rottenbren.dev.android.diary.activity;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.KeyEvent;

public class BaseActivity extends Activity {
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event){
		switch(keyCode){
			case KeyEvent.KEYCODE_BACK :
				new AlertDialog.Builder(this).setTitle("종료").setMessage("프로그램을 완전히 종료합니다.\n종료하시겠습니까?")
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {					
					public void onClick(DialogInterface dialog, int which) {
						moveTaskToBack(true);
						finish();
						
						ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
						am.restartPackage(getPackageName());
					}
				}).setNegativeButton("CANCEL", null).show();
		}
		return true;
	}
}
